#include "triangle.h"

Triangle::Triangle(std::vector<double> &data)
{
    x0 = data[0];
    y0 = data[1];
    x1 = data[2];
    y1 = data[3];
    x2 = data[4];
    y2 = data[5];
    angle = data[6];
}

void Triangle::setCoord(std::vector<double> &data)
{
    x0 = data[0];
    y0 = data[1];
    x1 = data[2];
    y1 = data[3];
    x2 = data[4];
    y2 = data[5];
    angle = data[6];
}

std::vector<double> Triangle::getCoord()
{
    std::vector<double> data;
    data.push_back(x0);
    data.push_back(y0);
    data.push_back(x1);
    data.push_back(y1);
    data.push_back(x2);
    data.push_back(y2);
    data.push_back(angle);
    return data;
}

std::pair<double, double> Triangle::centrePoint()
{
    return std::pair<double, double>((x0 + x1 + x2) / 3, (y0 + y1 + y2) / 3);
}

void Triangle::shift(double shiftX, double shiftY)
{
    x0 += shiftX;
    y0 += shiftY;
    x1 += shiftX;
    y1 += shiftY;
    x2 += shiftX;
    y2 += shiftY;
}

void Triangle::rotation(double rotAngle)
{
    angle = rotAngle;
}

void Triangle::extansion(double extCoef)
{    
    if(extCoef != 0)
    {
        std::pair<double, double> centreP = centrePoint();
        x0 = centreP.first + (x0 - centreP.first) * extCoef;
        y0 = centreP.second + (y0 - centreP.second) * extCoef;
        x1 = centreP.first + (x1 - centreP.first) * extCoef;
        y1 = centreP.second + (y1 - centreP.second) * extCoef;
        x2 = centreP.first + (x2 - centreP.first) * extCoef;
        y2 = centreP.second + (y2 - centreP.second) * extCoef;
    }
}

typeFigure Triangle::type()
{
    return triangle;
}

std::string Triangle::dataToString()
{
    return "Triangle " + std::to_string(x0) + " " + std::to_string(y0) + " "
                       + std::to_string(x1) + " " + std::to_string(y1) + " "
                       + std::to_string(x2) + " " + std::to_string(y2) + " "
                       + std::to_string(angle);
}
